package main

import (
	"context"
	"log"
	"net"

	"hello_server/pb"

	"google.golang.org/grpc"
)

type server struct {
	pb.UnimplementedHelloServer
}

// SayHello 一对一
func (s *server) SayHello(ctx context.Context, in *pb.Request) (*pb.Response, error) {
	return &pb.Response{
		Reply: "hello " + in.Name,
	},nil
}

func main() {
	lis, err := net.Listen("tcp", ":8081")
	if err != nil {
		log.Fatalf("net.Listen failed, err:%v\n", err)
	}

	s := grpc.NewServer()
	pb.RegisterHelloServer(s, &server{})

	// 程序启动之前 要注册服务到consul
	register2Consul()

	log.Println("server start...")
	if err := s.Serve(lis); err != nil {
		log.Fatalf("s.Serve failed, err:%v\n", err)
	}
}
